<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/jsp/common/common.jsp" %>
</head>
<body>

<div class="tableMainWarp">
  <div class="top-div"><em></em><span>&nbsp;>&nbsp;人员组织架构&nbsp;>&nbsp;职务管理</span></div>
  <div>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="search-table">
      <tr>
      	<td width="10%">域：</td>
      	<td width="15%"><select class="table-input" id="domain"><option value="">请选择</option></select></td>
      	<td width="10%">职务名称：</td>
      	<td width="15%"><input class="table-input" id="positionName" name="positionName" value=""/></td>
      	<td width="10%">职务级别：</td>
      	<td width="15%"><input class="table-input" id="positionLevel" name="positionLevel" value=""/></td>
      	<td width="10%">状态：</td>
      	<td width="15%">
      		<select class="table-input" id="state">
	  			<option value="">请选择</option>
	  			<option value="A">启用</option>
	  			<option value="F">禁用</option>
      	   	</select>
      	</td>
      </tr>	
      <tr>
      	<td></td>
      	<td></td>
      	<td></td>
      	<td></td>
      	<td colspan="4" align="right">
      	    <button class="btn-table" id="addButton">添加</button>
      		<button class="btn-table" id="deleteButton">删除</button>
      		<button class="btn-table" id="updateButton">修改</button>
	        <button class="btn-table" id="searchButton">查询</button>
        </td>
      </tr>	
      
    </table>
  </div>
  <div class="tablelist">
    <div class="tabcon" id="middleCon"  style="overflow: auto;"></div>
    <div id="paginationDiv"  class="page clearfix"></div>
  </div>
</div>


<script type="text/javascript">

$(document).ready(function(){
	
	var bodyHt=document.documentElement.clientHeight;
	var tableDivHeight = bodyHt-167;	
	$('#middleCon').height(tableDivHeight);
	
	getPageData();

	initTable();
	
	blindPageElement();
	
});

function blindPageElement(){

	$('#searchButton').on('click',function(){
		$('#middleCon').tablegrid('reload',{
			domainId : $('#domain').val(),
			positionName : $('#positionName').val(),
			positionLevel : $('#positionLevel').val(),
			state : $('#state').val()
		});
	});
}

function initTable(){
 	
	var url = "<%=basePath%>/biz/ou/employee/getPositionListData.do?";
	
	$('#middleCon').tablegrid({
		url: url,
		columns:[	
		         	{field:'id',ischeckbox:true,align:'center',width:2},
		   	        {field:'positionName',title:'职务名称',width:20},
		   	        {field:'positionLevel',title:'职务级别',width:10},
		   	     	{field:'positionDescription',title:'职务描述',width:58},
		   	     	{field:'state',title:'状态',formatter:stateFormatterFunction,width:10}
			    ],
	    isPagination:true,
	    resizeColumns : true,
	    pageConifg:{
	    	pageId : 'paginationDiv'
	    },
	    tableClass : 'table-form'
	});
}

function stateFormatterFunction(value, rowdata, index){
	if(value && value != ''){
		
		if(value == 'A'){
			return '启用';
		}else if(value == 'F'){
			return '禁用';
		}else{
			return '未知';
		}
		
	}else{
		return '';
	}
}

function getPageData(){
	
 	var url = '<%=basePath%>/biz/domain/getAllDomain.do';
 	
	$.ajax({  
        url:url,  
        type:'post',  
        dataType:'json',  
        success:function(data,textStatus,jqXHR){
        	$(data).each(function(index,entry){
        		var optionObj = $('<option></option>').append(entry.name).attr('value',entry.id);
        		$('#domain').append(optionObj);
        	});
        },  
        error:function(XMLHttpRequest,textStatus,errorThrown){  
        }                     
    });
	
}

</script>
</body>
</html>